package md.lanjing.com.module_deal_center.contact;

import android.content.Context;


import com.lxh.baselibray.mvp.BasePresent;
import com.lxh.baselibray.mvp.IBaseView;
import com.lxh.baselibray.net.NetCallBack;
import com.lxh.baselibray.net.ServiceGenerator;
import com.lxh.baselibray.util.Md5Utils;
import com.lxh.baselibray.util.SPUtils;
import com.lxh.baselibray.util.ToastUtils;

import md.lanjing.com.module_deal_center.api.DealApiService;
import com.lxh.baselibray.base.BaseResponce;
import md.lanjing.com.module_deal_center.bean.CancelOrderRequest;
import md.lanjing.com.module_deal_center.bean.SalingOrderResponce;
import com.lxh.baselibray.constant.Constant;
import retrofit2.Call;
import retrofit2.Response;

public class SalingOrderContact {
    public static class SalingOrderPresent extends BasePresent<ISalingOrderView> {
        public void querySalingOrder(final Context context){
            DealApiService service= ServiceGenerator.createService(DealApiService.class);
            int userId= SPUtils.getInt(Constant.USER_ID,-1,context);
            service.getSalingOrder(userId).enqueue(new NetCallBack<SalingOrderResponce>() {
                @Override
                public void onSuccess(Call<SalingOrderResponce> call, Response<SalingOrderResponce> response) {
                    if (getView()!=null){
                        getView().getSalingOrderData(response);
                    }
                }

                @Override
                public void onFailed() {
                    ToastUtils.showLongToast(context,"网络请求异常");
                }
            });

        }
        public void cancleSalingOrder(final Context context, String billId, String dealPwd){
            DealApiService service= ServiceGenerator.createService(DealApiService.class);
            int userId= SPUtils.getInt(Constant.USER_ID,-1,context);
            CancelOrderRequest request=new CancelOrderRequest(userId,billId, Md5Utils.stringToMD5(dealPwd));
            service.cancelOrder(request).enqueue(new NetCallBack<BaseResponce>() {
                @Override
                public void onSuccess(Call<BaseResponce> call, Response<BaseResponce> response) {
                    if (getView()!=null){
                        getView().getCancleOrderData(response);
                    }
                }

                @Override
                public void onFailed() {
                    ToastUtils.showLongToast(context,"网络请求异常");
                }
            });
        }
    }
    public interface ISalingOrderView extends IBaseView {
        void getSalingOrderData(Response<SalingOrderResponce> response);
        void getCancleOrderData(Response<BaseResponce> response);

    }
}
